package com.ithinkstudio.jeez.domain;

import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * @program: springboot-mybatis
 * @description: 返回结果
 * @author: fengzp
 * @create: 2020/04/14
 */
@Data
public class Result<T> implements Serializable {

    /**
     * 编码
     */
    private int code = 0;
    /**
     * 消息
     */
    private String msg;
    /**
     * 数据
     */
    private List<T> data;

    /**
     * 返回正常结果
     * @return
     */
    public static Result<String> getSuccess() {
        Result<String> result = new Result<>();
        result.setMsg("success");
        return result;
    }

    /**
     * 返回错误信息
     * @return
     */
    public static Result<String> getError() {
        Result<String> result = new Result<>();
        result.setCode(-1);
        result.setMsg("error");
        return result;
    }

    /**
     * 返回自定义错误信息
     * @param message
     * @return
     */
    public static Result getError(String message) {
        Result<String> result = new Result<>();
        result.setCode(-100);
        result.setMsg(message);
        return result;
    }
}
